package com.matrix.common.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 数据响应对象
 *    {
 *      code    ：返回码
 *      message ：返回信息
 *      //返回数据
 *      data：  ：{
 *
 *      }
 *    }
 */
@Data
@NoArgsConstructor
public class Result<T> implements Serializable {

    //返回码
    private Integer code;
    //返回信息
    private String message;
    // 返回数据
    private Object data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 200;
        result.message = "操作成功！";
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.code = 200;
        result.message = "操作成功！";
        result.data = object;
        return result;
    }

    public static <T> Result<T> error(ResultCodeMsg resultCodeMsg) {
        Result result = new Result();
        result.code = resultCodeMsg.getCode();
        result.message = resultCodeMsg.getMessage();
        return result;
    }
}
